package com.tql.pandian.controller;

import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.utils.SecurityUtils;
import com.ruoyi.system.api.model.LoginUser;
import com.tql.pandian.entity.dto.MaterialCaseDTO;
import com.tql.pandian.entity.dto.PanDianCaseDTO;
import com.tql.pandian.entity.dto.TqlPandianCaseDTO;
import com.tql.pandian.service.IPandianCaseService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 盘点库位表 tql_pandian_case_shop
 * 盘点库位盘点人关系表 tql_pandian_case_emp
 * 盘点库位物料关系表 tql_pandian_case_stap
 */
@ApiOperation("盘点库位")
@RestController
@RequestMapping("/pandianCase")
public class PandianCaseController extends BaseController {

    @Autowired
    private IPandianCaseService pandianCaseService;

    @ApiOperation("创建盘点库位-指定盘点人员")
    @Log(title = "创建盘点库位-指定盘点人员", businessType = BusinessType.OTHER)
    @GetMapping("/getPanDianStoreMan/{idCard}")
    public AjaxResult getPanDianStoreMan(@PathVariable String idCard){
        return success(pandianCaseService.getPanDianStoreMan(idCard));
    }

    @ApiOperation("创建盘点库位-指定盘点人员(获取登录表中)-new")
    @Log(title = "创建盘点库位-指定盘点人员(获取登录表中)-new", businessType = BusinessType.OTHER)
    @GetMapping("/getPanDianPerson")
    public AjaxResult getPanDianPerson(){
        return success(pandianCaseService.findPanDianPerson());
    }


    @ApiOperation("创建盘点库位-所含物料")
    @Log(title = "创建盘点库位-所含物料", businessType = BusinessType.OTHER)
    @PostMapping("/getContainMaterial")
    public AjaxResult getContainMaterial(@RequestBody MaterialCaseDTO materialCaseDTO){
        return success(pandianCaseService.getContainMaterial(materialCaseDTO));
    }


    @ApiOperation("创建盘点库位-dish-boom")
    @Log(title = "创建盘点库位-dish-bom", businessType = BusinessType.OTHER)
    @PostMapping("/getSemiMaterial")
    public AjaxResult getSemiMaterial(@RequestBody MaterialCaseDTO materialCaseDTO){
        return success(pandianCaseService.getSemiMaterial(materialCaseDTO));
    }

    @ApiOperation("获取所有物料大类")
    @Log(title = "获取所有物料大类", businessType = BusinessType.OTHER)
    @GetMapping("/getStapType")
    public AjaxResult getStapType(){
        return success(pandianCaseService.getStapType());
    }

    @ApiOperation("编辑库位-物料列表")
    @Log(title = "编辑库位-物料列表", businessType = BusinessType.OTHER)
    @GetMapping("/findCaseStap/{caseId}")
    public AjaxResult findCaseStap(@PathVariable Long caseId){
        return success(pandianCaseService.findCaseStap(caseId));
    }

    @ApiOperation("创建盘点库位-保存库位")
    @Log(title = "创建盘点库位-保存库位", businessType = BusinessType.INSERT)
    @PostMapping("/savePandianCase")
    public AjaxResult savePandianCase(@RequestBody TqlPandianCaseDTO tqlPandianCaseDTO){
        return success(pandianCaseService.savePandianCase(tqlPandianCaseDTO));
    }

    @ApiOperation("修改盘点库位-点击查看")
    @Log(title = "修改盘点库位-点击查看", businessType = BusinessType.UPDATE)
    @GetMapping("/getPandianCaseById/{id}")
    public AjaxResult getPandianCaseById(@PathVariable Long id){
        return success(pandianCaseService.getPandianCaseById(id));
    }











    @ApiOperation("修改盘点库位-点击保存")
    @Log(title = "修改盘点库位-点击保存", businessType = BusinessType.UPDATE)
    @PostMapping("/updatePandianCase")
    public AjaxResult updatePandianCase(@RequestBody TqlPandianCaseDTO tqlPandianCaseDTO){
        return success(pandianCaseService.updatePandianCase(tqlPandianCaseDTO));
    }

    @ApiOperation("盘点库位-下拉列表")
    @Log(title = "盘点库位-下拉列表", businessType = BusinessType.OTHER)
    @PostMapping("/queryPanDianCase")
    public AjaxResult queryPanDianCase(@RequestBody PanDianCaseDTO panDianCaseDTO){
        LoginUser loginUser= SecurityUtils.getLoginUser();
        Long userId=loginUser.getUserid();
        boolean flag= SecurityUtils.isAdmin(userId);
        if(!flag){
            panDianCaseDTO.setDeptCode(SecurityUtils.getLoginUser().getSysUser().getDeptCode());
        }
        return success(pandianCaseService.queryPanDianCase(panDianCaseDTO));
    }

    @ApiOperation("获取班组")
    @Log(title = "获取班组", businessType = BusinessType.OTHER)
    @GetMapping("/getTeamGroup")
    public AjaxResult getTeamGroup(){
        return success(pandianCaseService.getTeamGroup());
    }

    @ApiOperation("获取某库位某班组下所有的物料")
    @Log(title = "获取某库位某班组下所有的物料", businessType = BusinessType.OTHER)
    @GetMapping("/getStapByCaseId/{id}")
    public AjaxResult getStapByCaseId(@PathVariable String id){
        Long caseId=Long.parseLong(id);
        return success(pandianCaseService.getStapByCaseId(caseId));
    }












}
